package com.lut.edu.apm.payCenter.pojo;

import com.lut.edu.apm.commodityCenter.pojo.CommodityOrder;
import com.lut.edu.apm.payCenter.util.SnowFlake;
import lombok.Data;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 接收前端订单信息表
 *
 * @author Zhao Suzhen
 * @date `2024/4/10`
 */
@Data
public class SysOrder {
    // 订单编号
    private long out_trade_no;
    // 订单金额
    private double order_amount;
    // 优惠金额
    private double discount_amount;
    // 付款金额
    private double total_amount;
    // 支付授权码
    private String auth_code;
    // 支付场景
    private String scene;
    // 订单名称
    private String subject;
    // 产品码
    private String product_code;
    private String qr_pay_mode = "0";
    private String qrcode_width = "200";
    private String time_expire;
    private String userPhone;
    //    private List<OrderDetail> orderDetailsList;
    private List<Map<String, Object>> orderDetailsList;

    /**
     * @param totalAmount 总金额
     * @param subject     订单名称
     */
//    public SysOrder(double orderAmount,double discountAmount, double totalAmount, String subject, String userPhone, List<OrderDetail> orderDetailsList) {
    public SysOrder(double orderAmount, double discountAmount, double totalAmount, String subject, String userPhone, List<Map<String, Object>> orderDetailsList) {
        this.order_amount = orderAmount;
        this.discount_amount = discountAmount;
        this.total_amount = totalAmount;
        this.subject = subject;
        this.userPhone = userPhone;
        this.orderDetailsList = orderDetailsList;
    }

    /**
     * @param totalAmount 总金额
     * @param subject     订单名称
     * @param authCode    支付授权码
     */
    public SysOrder(double orderAmount, double discountAmount, double totalAmount, String subject, String authCode, String userPhone, List<Map<String, Object>> orderDetailsList) {
//    public SysOrder(double orderAmount,double discountAmount, double totalAmount, String subject, String authCode, String userPhone, List<OrderDetail> orderDetailsList) {
        this.order_amount = orderAmount;
        this.discount_amount = discountAmount;
        this.total_amount = totalAmount;
        this.subject = subject;
        this.auth_code = authCode;
        this.userPhone = userPhone;
        this.orderDetailsList = orderDetailsList;
    }

    public SysOrder() {
        this.out_trade_no = new SnowFlake(0, 0).nextId();
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 加两分钟
        LocalDateTime newTime = now.plusMinutes(3);
        // 格式化时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        this.time_expire = newTime.format(formatter);
    }

    public boolean isAuthCode() {
        return null != auth_code && !"".equals(auth_code);
    }
}
